/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cput.tp.patterns.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Malotana
 */
public class FlyweigtFactory {
    public static FlyweigtFactory flyweigtFactory;
    private Map<String ,FlyWeight> flyWeightPool;
    
    public FlyweigtFactory(){
        flyWeightPool = new HashMap<String,FlyWeight>();
    } 
    public static FlyweigtFactory getInstance(){
         if(flyweigtFactory == null){
           flyweigtFactory = new FlyweigtFactory();
         }
         return flyweigtFactory;
    }
    
    public FlyWeight getFlyweight(String key){
        if(flyWeightPool.containsKey(key)){
            return flyWeightPool.get(key);
        }else{
            FlyWeight flyweight;
            if("add".equals(key)){
                flyweight= new FlyWeightAdapter();
            }else{
              flyweight = new FlyweightMultiplier(); 
        }flyWeightPool.put(key, flyweight);
        return flyweight;
    }  
  }
}
